"""
Created on 2024/8/29 上午11:13
@author:刘飞
@description:
角色管理相关接口逻辑
"""
from yc_django_utils.crud_mixin import FastCrudMixin
from yc_django_utils.viewset import CustomModelViewSet
from yc_django_utils.filters import CoreModelFilterBackend
from ..utils.field_permission import FieldPermissionMixin
from ..utils.custom_permission import CustomPermission
from ..utils.data_level_permission_filter import DataLevelPermissionsFilter
from ..models import Role
from .role_serializers import RoleSerializer, RoleCreateUpdateSerializer


class RoleViewSet(CustomModelViewSet, FastCrudMixin, FieldPermissionMixin):
    """
    角色管理接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """
    queryset = Role.objects.all()
    serializer_class = RoleSerializer
    create_serializer_class = RoleCreateUpdateSerializer
    update_serializer_class = RoleCreateUpdateSerializer
    extra_filter_class = [CoreModelFilterBackend, DataLevelPermissionsFilter]
    permission_classes = [CustomPermission]
    search_fields = ['name', 'key']